import { defineStore } from 'pinia';


export  const useAppStore = defineStore('app',{
  persist: true,
  state: (): AppStateType => {
    return {
      token: '',
      user: undefined
    };
  },
  actions: {
    saveOrUpdate(token: string) {
      this.token = token
    },
    clearData() {
      this.$reset();
    },
    updateUser(user: UserType) {
      this.user = user
    }
  },
});

export type AppStateType = {
  token?: string,
  user?: UserType
}

export type UserType = {
  id: string,
  username: string,
  nickname: string,
  avatar: string
}